﻿using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Text;

namespace HongYeSystemWebApi.Templet.Core
{
    public class CConfigure
    {
        public static string SecretKey { get; set; }
        public static string Issuer { get; set; }
        public static string Audience { get; set; }
        public static int Expired { get; set; }
        public static DateTime NotBefore => DateTime.UtcNow;
        public static DateTime IssuedAt => DateTime.UtcNow;
        public static DateTime Expiration => IssuedAt.AddHours(Expired);
        private static SecurityKey SigningKey => new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SecretKey));
        public static SigningCredentials SigningCredentials =>
            new SigningCredentials(SigningKey, SecurityAlgorithms.HmacSha256);

        public static void Configure(IConfiguration config)
        {
            SecretKey = config["JwtConfig:SecretKey"];
            Issuer = config["JwtConfig:Issuer"];
            Audience = config["JwtConfig:Audience"];
            Expired = Convert.ToInt32(config["JwtConfig:Expired"]);
        }
    }
}
